package com.jackie.coupon.customer.api.enumss;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Optional;
import java.util.stream.Stream;

/**
 * CouponStatus
 *
 * @author Jackie Hou
 * @date 2023/11/18 23:40
 * @version 1.0
 */
@Getter
@AllArgsConstructor
public enum CouponStatus {
    AVAILABLE("未使用", 1),
    USED("已用", 2),
    INACTIVE("已注销", 3);


    private String desc;
    private Integer code;

    public static CouponStatus convert(Integer code) {
        if (code == null) {
            return null;
        }

        return Stream.of(values())
                .filter(e -> e.code.equals(code))
                .findFirst()
                .orElse(null);
    }
}
